#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""生成加密API凭证文件"""
import os
import sys

sys.path.append(os.path.dirname(os.path.abspath(__file__)))

from utils.security_utils import SecurityUtils


def main():
    """主函数"""
    # 设置开发模式环境变量，使用测试密钥
    os.environ['DEVELOPMENT_MODE'] = 'true'
    
    try:
        # 创建测试凭证数据
        credentials = {
            "api_key": "demo_app_id",
            "api_secret": "demo_secret_key",
            "created_at": "2025-08-24 09:30:00"
        }
        
        # 获取配置路径
        config_path = SecurityUtils.get_secure_config_path()
        print(f"将生成加密凭证到: {config_path}")
        
        # 安全保存凭证
        success = SecurityUtils.secure_save_credentials(config_path, credentials)
        
        if success:
            print("加密API凭证文件生成成功！")
            print("系统现在应该能够正确加载API凭证了。")
        else:
            print("生成加密API凭证文件失败。")
    except Exception as e:
        print(f"生成凭证时发生错误: {str(e)}")


if __name__ == "__main__":
    main()